#include "mywidget.h"
#include "ui_mywidget.h"

myWidget::myWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::myWidget)
{
    ui->setupUi(this);
    this->Init_widget();



}

myWidget::~myWidget()
{
    delete ui;
}

void myWidget::Init_widget()
{
    ui->pic_label->setStyleSheet("border-image:url(:/new/prefix1/image/design_drawing.png);");
}


void myWidget::on_Identify_btn_pressed()
{
    pos_x=5;
    qDeleteAll(ui->pic_label->findChildren<QObject *>());

    if((ui->air_cleaner_num->text()!=NULL)&&(ui->HCHO_monitor_num->text()!=NULL)&&(ui->air_monitoring_station_num->text()!=NULL)&&(ui->PM_monitor_num->text()!=NULL)&&(ui->humiture_monitor_num->text()!=NULL)&&(ui->visual_presentation_num->text()!=NULL))
    {
        int air_cleaner_count= ui->air_cleaner_num->text().toInt();
        int HCHO_monitor_count= ui->HCHO_monitor_num->text().toInt();
        int air_monitoring_station_count=ui->air_monitoring_station_num->text().toInt();
        int PM_monitor_count= ui->PM_monitor_num->text().toInt();
        int humiture_monitor_count= ui->humiture_monitor_num->text().toInt();
        int visual_presentation_count= ui->visual_presentation_num->text().toInt();

        myWidget::set_instrument(instrument::air_cleaner,air_cleaner_count,pos_x,pos_y,size_x,size_y);
        pos_x+=90;
        myWidget::set_instrument(instrument::HCHO_monitor,HCHO_monitor_count,pos_x,pos_y,size_x,size_y);
        pos_x+=90;
        myWidget::set_instrument(instrument::air_monitoring_station,air_monitoring_station_count,pos_x,pos_y,size_x,size_y);
        pos_x+=90;
        myWidget::set_instrument(instrument::PM_monitor,PM_monitor_count,pos_x,pos_y,size_x,size_y);
        pos_x+=90;
        myWidget::set_instrument(instrument::humiture_monitor,humiture_monitor_count,pos_x,pos_y,size_x,size_y);
        pos_x+=90;
        myWidget::set_instrument(instrument::visual_presentation,visual_presentation_count,pos_x,pos_y,size_x,size_y);
        pos_x+=90;
    }
    else
    {
        QMessageBox mybox;
        mybox.about(this,QString("警告!"),QString("请填入仪器台数！"));
    }
}


void myWidget::set_instrument(const instrument::Instrument_type &instrument_type,int count,int x,int y, int sizex, int sizey)
{
    for(int i=0;i<count;i++)
    {
         inst=new instrument(ui->pic_label);
         inst->setGeometry(x,y,sizex,sizey);
         inst->set_string(QString::number(i + 1));
         inst->set_Image(instrument_type);
         inst->show();

    }

}


void myWidget::on_clear_config_btn_pressed()
{
    qDeleteAll(ui->pic_label->findChildren<QObject *>());
    ui->air_cleaner_num->clear();
    ui->HCHO_monitor_num->clear();
    ui->air_monitoring_station_num->clear();
    ui->PM_monitor_num->clear();
    ui->humiture_monitor_num->clear();
    ui->visual_presentation_num->clear();
}
